/*
 *  clhelper.h
 *  Sandbox
 *
 *  Created by Joshua Lewis on 10/28/10.
 *  Routines for reading system info and running OpenCL code.
 *
 */

#ifndef CLHELPER_H
#define CLHELPER_H

#include <stdio.h>
#include <stdlib.h>

#include <assert.h>
#include <string.h>

#include <OpenCL/OpenCL.h>
#include <sys/stat.h>

#include "timer.h"
#include "distance.h"
#include "linkage.h"

typedef struct {
	char type[3];
	char devicename[1024];
	char vendor[1024];
	unsigned long int local_mem_size;
	unsigned long int global_mem_size;
	unsigned long int global_cache_size;
	unsigned long int global_cacheline_size;
	unsigned int available;
} CLDevice;

cl_device_id cpu[16], gpu[16];
cl_device_id testdevice;
cl_uint n_CPUs, n_GPUs;
cl_int GPU_FOUND, CPU_FOUND;
CLDevice * CPUs, * GPUs;

cl_context context;
cl_command_queue queue;
cl_program program;
cl_kernel kernel;
cl_event event;
size_t localsize;
int err;

cl_mem clinput, cloutput, clbasestart;

void getOpenCLInfo();
char * load_program_source(const char *filename);
float * row_to_col(float * data, int N, int D);
unsigned int * zeros(int N);
double * dzeros(int N);
void initQueue();
void createProgram(const char * source);
void createKernel(char * name);

double gpuPdist_CL(int N, int D, float *data);
void testCL_prune(int N, float *distance);
double testCL(unsigned int N, unsigned int D, unsigned int blocksize, int n_tests,float * data, float *comparison);
void runTests(int N, int D, int n_conds,float * data);

#endif